import { message } from "antd";
import { getToken } from "../utils";
import { Navigate } from "react-router-dom";
import { useEffect } from "react";

export function AuthRoute({children}) {
    const token = getToken()

    useEffect(() => {
        if (!token) {
          message.error('请先登录');
        }
      }, [token]);
    if(token) {
        return <>{children}</>
    } else {
        return <Navigate to='/login' replace/>
    }
}